postgrest.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { components } from 'api-types'
  2. import { NextApiRequest, NextApiResponse } from 'next'
  3. import apiWrapper from '@/lib/api/apiWrapper'
  4. export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
  5. async function handler(req: NextApiRequest, res: NextApiResponse) {
  6. const { method } = req
  7. switch (method) {
  8. case 'GET':
  9. return handleGet(req, res)
  10. default:
  11. res.setHeader('Allow', ['GET'])
  12. res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
  13. }
  14. }
  15. const handleGet = async (_req: NextApiRequest, res: NextApiResponse) => {
  16. const responseObj: components['schemas']['GetPostgrestConfigResponse'] = {
  17. db_anon_role: 'anon',
  18. db_extra_search_path: process.env.PGRST_DB_EXTRA_SEARCH_PATH ?? 'public',
  19. db_schema: process.env.PGRST_DB_SCHEMAS ?? 'public,storage,graphql_public',
  20. jwt_secret:
  21. process.env.AUTH_JWT_SECRET ?? 'super-secret-jwt-token-with-at-least-32-characters-long',
  22. max_rows: Number(process.env.PGRST_DB_MAX_ROWS) || 1000,
  23. role_claim_key: '.role',
  24. }
  25. return res.status(200).json(responseObj)
  26. }